/*
 * Copyright (C), 2014-2015, 杭州小卡科技有限公司
 * Created by ciwei@xiaokakeji.com on 2016/06/05.
 */
package com.micromall.admin;

import com.google.common.collect.Maps;
import com.micromall.service.AdminStatisticsService;
import com.micromall.web.resp.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * @author ciwei@xiaokakeji.com
 * @date 2016/06/05.
 */
@RestController
@RequestMapping(value = "/admin")
public class AdminIndexController {

	private static Map<String, Object>    statisticsData;
	@Resource
	private        AdminStatisticsService adminStatisticsService;

	/**
	 * 首页统计
	 *
	 * @return
	 */
	@RequestMapping(value = "/index_statistics")
	public ResponseEntity<?> index_statistics() {
		if (statisticsData == null) {
			Map<String, Object> data = Maps.newHashMap();
			data.put("statistics", adminStatisticsService.statistics());
			data.put("lastTime", new Date());
			statisticsData = data;
		}
		return ResponseEntity.Success(statisticsData);
	}

	@RequestMapping(value = "/index_statistics_reload")
	public ResponseEntity<?> index_statistics_reload() {
		Map<String, Object> data = Maps.newHashMap();
		data.put("statistics", adminStatisticsService.statistics());
		data.put("lastTime", new Date());
		statisticsData = data;
		return ResponseEntity.Success(statisticsData);
	}
}
